﻿using System;
using System.Collections;
using System.Configuration;
using System.Linq;
using System.Data;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using Wsitech.Model;
using System.Collections.Generic;
using Wsitech.BLL;



public partial class Backend_menu : BackendPageBase
{
    private IList<string> funIdList = new List<string>();
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            if (base.IsVerified)
            {
                IList<AdminRole> roleList = AdminRoleBLL.Instance.GetRoleListByUserId(base.VerifiedUser.UserID);
                foreach (AdminRole role in roleList)
                {
                    IList<RoleFuncRela> relaList = RoleFuncRelaBLL.Instance.GetListByRoleId(role.RoleID);
                    foreach (RoleFuncRela rela in relaList)
                    {
                        if (!funIdList.Contains(rela.FuncId))
                        {
                            funIdList.Add(rela.FuncId);
                        }
                    }
                }
            }
            bindMenu();
        }
    }

    private void bindMenu()
    {
        repPMenu.DataSource = SiteMapInfoBLL.Instance.GetBackendParentList().Where(s => funIdList.Contains(s.SitemapId));
        repPMenu.DataBind();
    }

    protected object getSiteMapByPid(string parentId)
    {
        return SiteMapInfoBLL.Instance.GetBackendListByParentId(parentId).Where(s => funIdList.Contains(s.SitemapId));
    }

    protected string getBackUrl(SiteMapInfo info)
    {
        if (info.BackUrl.IndexOf('?') != -1)
        {
            return info.BackUrl + "&sitemapId=" + info.SitemapId;
        }
        else
        {
            return info.BackUrl + "?sitemapId=" + info.SitemapId;
        }
    }
}
